package com.example.controller;

import com.alibaba.fastjson.JSON;
import com.example.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author ：songxusheng
 * @date ：Created in 2022/2/28 13:56
 * @description：队列生产者
 * @version: $
 */
@RestController
@RequestMapping("/consumer")
public class Queue_Produce {

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Value("${consumerQueue}")
    private String myQueue;

    @PostMapping("send")
    public void produceMsg(){
        jmsMessagingTemplate.convertAndSend(myQueue,"我是一条消息");
        System.out.println("消息推送到MQ成功");
    }

    @PostMapping("send1")
    public void produceMsg1(){
        User user = new User(1,"张三","123456");
        String s = JSON.toJSONString(user);
        jmsMessagingTemplate.convertAndSend(myQueue,s);
        System.out.println("User推送到MQ成功");
    }
}
